﻿<UserControl xmlns:toolkit="http://schemas.microsoft.com/winfx/2006/xaml/presentation/toolkit"  x:Class="uTorrentSL.Views.TorrentView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
             xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
             xmlns:cx="clr-namespace:uTorrentSL.Behaviors"
             xmlns:cv="clr-namespace:uTorrentSL.Converters"
             xmlns:GalaSoft_MvvmLight_Command="clr-namespace:GalaSoft.MvvmLight.Command;assembly=GalaSoft.MvvmLight.Extras.SL4"
             mc:Ignorable="d"
             DataContext="{Binding TorrentViewModel, Source={StaticResource Locator}}">
    <UserControl.Resources>
        <cv:MultiplyConverter x:Key="MultiConv"/>
		<Style x:Key="ListBoxItemStyle1" TargetType="ListBoxItem">            
			<Setter Property="Padding" Value="3"/>            
			<Setter Property="HorizontalContentAlignment" Value="Stretch"/>
		</Style>

        <Style x:Key="myMarg" TargetType="Button" >
            <Setter Property="Margin" Value="0,0,5,0"/>
        </Style>
    </UserControl.Resources>
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="*"/>
            <RowDefinition Height="Auto"/>
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="Auto"/>
            <ColumnDefinition Width="*"/>
        </Grid.ColumnDefinitions>
        <StackPanel Grid.Row="1" Grid.Column="0" Margin="10,0,0,0" Grid.RowSpan="2">
            <StackPanel.Resources>
            </StackPanel.Resources>
            <Button HorizontalContentAlignment="Left" Margin="0,0,5,3" MinHeight="0" MinWidth="0" Padding="4,4,4,8" FontSize="18"
                    HorizontalAlignment="Stretch" Content="start" Command="{Binding StartTorrent}"/>

            <Button HorizontalContentAlignment="Left" MinHeight="0" MinWidth="0" Padding="4,4,4,8" 
                    FontSize="18" HorizontalAlignment="Stretch" Margin="0,0,5,3"  Content="force start"  Command="{Binding ForceStartTorrent}"/>

            <Button HorizontalContentAlignment="Left" MinHeight="0" MinWidth="0" Padding="4,4,4,8" FontSize="18"
                    HorizontalAlignment="Stretch" Content="stop"  Margin="0,0,5,3" 
                 Command="{Binding StopTorrent}"/>
            <Button HorizontalContentAlignment="Left" MinHeight="0" MinWidth="0" Padding="4,4,4,8" 
                    FontSize="18" HorizontalAlignment="Stretch"  Margin="0,0,5,3" Content="remove" Command="{Binding RemoveTorrent}"/>
                    
            <Button HorizontalContentAlignment="Left" MinHeight="0" MinWidth="0" Padding="4,4,4,8"
                    FontSize="18" HorizontalAlignment="Stretch"  Margin="0,0,5,3" Content="remove + data" 
                    Command="{Binding RemoveDataTorrent}"/>
        </StackPanel>
        <TextBlock Text="{Binding Path=SelectedTorrent.Name}" Margin="8,8,8,8" Grid.ColumnSpan="2" FontSize="16"/>
        <toolkit:DataForm CurrentItem="{Binding SelectedTorrent, Mode=TwoWay}" LabelPosition="Auto" AutoGenerateFields="False"  Grid.Row="1" Grid.Column="1">
            <toolkit:DataForm.DataFieldStyle>
            	<Style TargetType="toolkit:DataField">
            		<Setter Property="LabelPosition" Value="Top"/>        	
				</Style>         
			</toolkit:DataForm.DataFieldStyle>
			<toolkit:DataForm.EditTemplate>
			<DataTemplate>
			<StackPanel>
				<ProgressBar Height="10" Width="600" Value="{Binding ProgressPercent, Converter={StaticResource MultiConv}, ConverterParameter=100}" HorizontalAlignment="Left" Margin="10,5,5,5"/>
				<Grid>
					<Grid.ColumnDefinitions>
						<ColumnDefinition Width="Auto"/>
						<ColumnDefinition/>
					</Grid.ColumnDefinitions>
					<toolkit:DataField VerticalAlignment="Top" PropertyPath="StatusMessage" Label="Status" LabelPosition="Top">
		                <TextBlock  Text="{Binding StatusMessage}"/>
		            </toolkit:DataField>
					<toolkit:DataField Grid.Column="1" PropertyPath="Label" Label="Label" LabelPosition="Top">
		                <TextBox Text="{Binding Label, Mode=TwoWay}"/>
		            </toolkit:DataField>
				</Grid>
				<toolkit:WrapPanel>
		            <toolkit:DataField PropertyPath="SpeedDownloadBitsFormatted" Label="Download Speed">
		                <TextBlock Text="{Binding SpeedDownloadBitsFormatted}"/>
		            </toolkit:DataField>
					<toolkit:DataField PropertyPath="SizeDownloadedFormatted" Label="Downloaded">
		                <TextBlock Text="{Binding SizeDownloadedFormatted}"/>
		            </toolkit:DataField>
					<toolkit:DataField PropertyPath="SizeTotalFormatted" Label="Size">
		                <TextBlock Text="{Binding SizeTotalFormatted}"/>
		            </toolkit:DataField>
				</toolkit:WrapPanel>
				<toolkit:DataField Label="Files">
					<ListBox ItemsSource="{Binding Files, Mode=TwoWay}" ItemContainerStyle="{StaticResource ListBoxItemStyle1}" HorizontalAlignment="Stretch">
						<ListBox.ItemTemplate>
							<DataTemplate>
							<Grid>
								<Grid.ColumnDefinitions>
									<ColumnDefinition Width="Auto"/>
									<ColumnDefinition Width="*"/>
								</Grid.ColumnDefinitions>	
								<TextBlock Text="{Binding Name}" Padding="0,0,0,10"/>
								<Grid Grid.Column="1" HorizontalAlignment="Right">
									<Grid.ColumnDefinitions>
										<ColumnDefinition/>
										<ColumnDefinition/>
										<ColumnDefinition/>
									</Grid.ColumnDefinitions>
									<TextBlock Text="{Binding SizeDownloadedFormatted}"/>
									<TextBlock Text="/" Grid.Column="1"/>
									<TextBlock Text="{Binding SizeTotalFormatted}" Grid.Column="2"/>
								</Grid>
							</Grid>
							</DataTemplate>
						</ListBox.ItemTemplate>
					</ListBox>
				</toolkit:DataField>
			</StackPanel>
			</DataTemplate>
			</toolkit:DataForm.EditTemplate>
        </toolkit:DataForm>
		
		
    </Grid>
</UserControl>
